﻿//----------------------------------------------------------------
// Copyright (c) 2011-2013 
// All rights reserved.
// Author: Ben DaoWei 
// Contact: bendaowei@gmail.com
// Web Link: http://xnaeditor.codeplex.com
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using MdxLib.Model;

namespace UnityEngine.Graphics.Shader
{
    public class EffectManager : IDisposable
    {
        private EffectManager()
        {
            Shader = new StandardShader(null);
        }

        public static void SingletonDispose()
        {
            if (_Instance != null)
                _Instance.Dispose();
            _Instance = null;
        }

        ~EffectManager()
        {
            this.Dispose(false);
        }

        public void Dispose()
        {
            this.Dispose(true);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.Shader != null)
                    this.Shader.Dispose();
            }
        }

        private static EffectManager _Instance = null;
        public static EffectManager Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new EffectManager();
                return _Instance;
            }
        }

        public Shader Shader { get; set; }

        public void ResetDevice(GraphicsDevice device = null)
        {
            Shader.ResetDevice(device);
        }

        public void Render()
        {
            Shader.Render();
        }

        public GraphicsDevice GraphicsDevice
        {
            get
            {
                return Shader.GraphicsDevice;
            }
        }
    }
}
